package com.example.javabasic.suanfa.jiandan.翻转链表;

import java.util.Stack;

/**
 * @description 翻转链表
 * @Author Lin FuYuan
 * @date 2021/5/12
 */
public class Reverse {

    public static void main(String[] args) {
        Node node = new Node(1);
        int i = 1;
        Node noder = node;
        while (i < 6) {
            Node nn = new Node(++i);
            noder.setNext(nn);
            noder = nn;
        }
        Stack stack = new Stack();
        while (node != null) {
            stack.push(node);
            node = node.getNext();
        }

        Node res = (Node) stack.pop();
        Node cur = res;
        while (cur != null && !stack.empty()) {
            Node n = (Node) stack.pop();
            n.setNext(null);
            cur.setNext(n);
            cur = cur.getNext();
        }

        System.out.println(res);
    }
}
